package cn.wolfcode.shop.cloud.mq.listener;

import cn.wolfcode.shop.cloud.mq.MQConstants;
import cn.wolfcode.shop.cloud.web.controller.OrderInfoController;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

/**
 * Created by wolfcode-lanxw
 */
@RocketMQMessageListener(
        topic = MQConstants.SECKILL_ORDER_TOPIC,
        selectorExpression = MQConstants.CLEAR_STOCK_COUNT_FLAG_ORDER_TAG,
        consumerGroup = MQConstants.CLEAR_STOCK_COUNT_FLAG_ORDER_CONSUMER_GROUP,
        messageModel = MessageModel.BROADCASTING
)
@Component
@Slf4j
public class ClearStockCountMQListener implements RocketMQListener<Long> {

    @Override
    public void onMessage(Long seckillId) {
        log.info("[清除库存标记消息] 收到消息, 清除库存:{}", seckillId);
        // 将本地售完标记设置为 false
        OrderInfoController.STOCK_OVER_FLAG_MAP.put(seckillId, false);
    }
}
